﻿Imports System.Text
Namespace DataMaster
    Public Class clsMSTBARCODE
        Inherits ADODBU.Recordset

        Private mFieldList As New ArrayList
        Private mStrFieldList As String
        Private mStrSql As String
        Public Sub New()
            mFieldList.Add("MSTBARCODE.BARCODE")
            mFieldList.Add("MSTBARCODE.ARTCEXT")
            mFieldList.Add("MSTBARCODE.SIZE")
            mFieldList.Add("MSTBARCODE.COLOR")
            mFieldList.Add("MSTBARCODE.BARTYPE")
            mFieldList.Add("MSTBARCODE.BARSTAT")
            mFieldList.Add("MSTBARCODE.BARDCRE")
            mFieldList.Add("MSTBARCODE.BARDMAJ")
            mFieldList.Add("MSTBARCODE.BARUTIL")
            mFieldList.Add("MSTBARCODE.BARPROG")
            mFieldList.Add("MSTBARCODE.BARDESCR")
            mStrSql = "Select BARCODE,ARTCEXT,SIZE,COLOR,BARTYPE,BARSTAT,BARDCRE,BARDMAJ,BARUTIL,BARPROG,BARDESCR from MSTBARCODE  "
        End Sub

        Public Overloads Sub Open(cCriteria As String)
            Dim cSql As String
            cSql = mStrSql & cCriteria
            MyBase.AddPK("BARCODE")
            MyBase.AddPK("ARTCEXT")
            MyBase.AddPK("SIZE")
            MyBase.AddPK("COLOR")
            MyBase.IsCanUpdate = True
            Try
                MyBase.Open(cSql, "MSTBARCODE", Me.DbConn)
            Catch e As Exception
                Me.ErrMessage = e.Message
            End Try
        End Sub


        Public Function GetRowList(dbConn As ADODBU.dbConn, cCriteria As String) As ADODBU.RowClassList(Of clsMSTBARCODERow)
            Dim cmd As System.Data.IDbCommand = dbConn.DBAFactory.GetCommand
            cmd.CommandText = Me.mStrSql & cCriteria
            cmd.CommandType = CommandType.Text
            cmd.Connection = dbConn.Connection
            Return GetDataFromReader(cmd.ExecuteReader)
        End Function

        Public Function GetRowList() As ADODBU.RowClassList(Of clsMSTBARCODERow)
            Return Me.GetDataFromReader(Me.DataTable.CreateDataReader)
        End Function
        Private Function GetDataFromReader(ByVal rdr As IDataReader) As ADODBU.RowClassList(Of clsMSTBARCODERow)
            Dim colData As New ADODBU.RowClassList(Of clsMSTBARCODERow)
            Dim xData As clsMSTBARCODERow
            Dim buffer() As Byte
            Dim len As Long
            Dim mStr As New System.IO.MemoryStream

            Do While rdr.Read
                xData = New clsMSTBARCODERow()
                If Not rdr.IsDBNull(0) Then
                    xData.BARCODE = rdr.GetString(0)
                End If
                If Not rdr.IsDBNull(1) Then
                    xData.ARTCEXT = rdr.GetString(1)
                End If
                If Not rdr.IsDBNull(2) Then
                    xData.SIZE = rdr.GetString(2)
                End If
                If Not rdr.IsDBNull(3) Then
                    xData.COLOR = rdr.GetString(3)
                End If
                If Not rdr.IsDBNull(4) Then
                    xData.BARTYPE = rdr.GetInt32(4)
                End If
                If Not rdr.IsDBNull(5) Then
                    xData.BARSTAT = rdr.GetInt32(5)
                End If
                If Not rdr.IsDBNull(6) Then
                    xData.BARDCRE = rdr.GetDateTime(6)
                End If
                If Not rdr.IsDBNull(7) Then
                    xData.BARDMAJ = rdr.GetDateTime(7)
                End If
                If Not rdr.IsDBNull(8) Then
                    xData.BARUTIL = rdr.GetString(8)
                End If
                If Not rdr.IsDBNull(9) Then
                    xData.BARPROG = rdr.GetString(9)
                End If
                If Not rdr.IsDBNull(10) Then
                    xData.BARDESCR = rdr.GetString(10)
                End If
                colData.Add(xData)
            Loop
            rdr.Close()
            rdr.Dispose()
            Return colData
        End Function
        Public Function GetReader(ByVal dbConn As ADODBU.dbConn, ByVal cCriteria As String) As IDataReader
            Dim cmd As System.Data.IDbCommand = dbConn.DBAFactory.GetCommand
            cmd.CommandText = Me.mStrSql & cCriteria
            cmd.CommandType = CommandType.Text
            cmd.Connection = dbConn.Connection
            Return cmd.ExecuteReader
        End Function
        Public Function GetClassRow() As clsMSTBARCODERow
            Dim crData As New clsMSTBARCODERow
            crData = GetClassRow(Me.GetCurrentDataRow)
            Return crData
        End Function


        Public Function GetClassRow(recdata As ADODBU.Recordset) As clsMSTBARCODERow
            Dim crData As clsMSTBARCODERow
            crData = New clsMSTBARCODERow(recdata.GetCurrentDataRow)
            Return crData
        End Function


        Public Function GetClassRow(recdata As DataRow) As clsMSTBARCODERow
            Return New clsMSTBARCODERow(recdata)
        End Function


        Public Function SaveClassRow(crData As clsMSTBARCODERow, lAddnew As Boolean, Optional lTransaction As Boolean = False) As Boolean
            Dim lSavedata As Boolean
            If lAddnew Then
                MyBase.AddNew()
            End If
            crData.DataSource = Me
            crData.SaveToDataSource()
            lSavedata = True
            Try
                MyBase.Update(lTransaction)
                If MyBase.ErrMessage.Length <> 0 Then
                    lSavedata = False
                End If
            Catch e As Exception
                lSavedata = False
            End Try
            Return lSavedata
        End Function


    End Class
End Namespace